//
//  XVCRefuseVisitor.m
//  ppkc2016
//
//  Created by 拼凑的断音 on 16/4/11.
//  Copyright © 2016年 拼凑的断音. All rights reserved.
//

#import "XVCRefuseVisitor.h"
#import "XVVTextViewWithPlaceholder.h"
#import "XXTool.h"

@interface XVCRefuseVisitor ()

@property (nonatomic) XVVTextViewWithPlaceholder *inputRefuseReason;

@property (nonatomic) DKButton *reply;

@end

@implementation XVCRefuseVisitor

-(XVVTextViewWithPlaceholder*)inputRefuseReason
{
    if (_inputRefuseReason==nil)
    {
        _inputRefuseReason =[[XVVTextViewWithPlaceholder alloc] init];
        _inputRefuseReason.textFont = [XXTool systemFontOfSize:16];
        _inputRefuseReason.backgroundColor = [UIColor whiteColor];
        _inputRefuseReason.placeholder = NSLocalizedString(@"可以协商新的时间或婉拒对方的预约", nil);
        [_inputRefuseReason setPlaceholder_textColor:[XXTool colorWithHexString:@"989898"]];
        [self.view addSubview:_inputRefuseReason];
    }
    return _inputRefuseReason;
}

-(DKButton*)reply
{
    if (_reply==nil)
    {
        _reply = [[DKButton alloc] init];
        _reply.text = NSLocalizedString(@"回复", nil);
        _reply.textColor = [XXTool colorWithProject];
        [_reply setColor:[UIColor whiteColor] ForState:DKButtonStateNormal];
        _reply.layer.borderColor = [XXTool colorWithProject].CGColor;
        _reply.layer.cornerRadius = 5;
        _reply.layer.borderWidth = 1.8;
        _reply.font = [XXTool systemFontOfSize:16.5f];
        [_reply addTarget:self Select:@selector(clickReplyButton) ForEvent:DKButtonEventPressedEnd];
        [self.view addSubview:_reply];
    }
    return _reply;
}

-(void)initUI
{
    [self.navigationItem setTitle:NSLocalizedString(@"拒绝", nil)];
    self.view.backgroundColor = [XXTool colorWithBackGround];
    [self inputRefuseReason];
    [self reply];
}

-(void)refreshLayout:(CGRect)frame
{
    _inputRefuseReason.frame = CGRectMake(0, 0, frame.size.width
                                          , 235);
    _reply.frame = CGRectMake(15
                              , _inputRefuseReason.frame.size.height+_inputRefuseReason.frame.origin.y+20
                              , frame.size.width-30
                              , 37);
}

-(void)clickReplyButton
{
    [DKHTTPRequest sendDataWithShortUrl:@"msg_accept"
                                  Param:[XXTool formatStringWithLanguage:[NSString stringWithFormat:@"userid=%@&passwd=%@&orderid=%@&accept=2&value=%@",[UserInfo shareUserInfo].userID,[UserInfo shareUserInfo].userPassword,self.appointmentPersonID,[_inputRefuseReason inputTextString]]]
                             ImageArray:nil
                                TimeOut:10
                             Completion:^BOOL(NSMutableDictionary *serverDic, DKHTTPResponseType bufferType) {
                                 if ([[serverDic objectForKey:@"code"] intValue]==200)
                                 {
                                     [_inputRefuseReason setinputTextString:@""];
                                     [SVProgressHUD showSuccessWithStatus:NSLocalizedString(@"已成功婉拒", nil)];
                                     if (self.useBlock)
                                     {
                                         self.useBlock();
                                     }
                                 }
                                 return YES;
                             } IsBuffering:YES
                      IsNeedReplaceWrap:NO
                        IsUseUpLoadHead:NO];
}

#pragma mark api
+(void)pushRefuseVisitorVCWithSourceVC:(UIViewController *)sourceVC apPersonID:(NSString *)apID completion:(void (^)())block
{
    XVCRefuseVisitor *vc = [[XVCRefuseVisitor alloc] init];
    vc.appointmentPersonID = apID;
    vc.useBlock = block;
    if (sourceVC)
    {
        [sourceVC.navigationController pushViewController:vc animated:YES];
    }
}

@end
